define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	
	$scope.form.fk_class = params.id;
	$scope.form.fk_unit = params.fk_unit;
	$scope.form.type =  params.type;

	//查询教职工数据
	$scope.find = function(){
		httpService.postpage(app.urls.teacher_selectToList,$scope.form,function(data){		
			if("0000" === data.code){
    			$scope.rows = data.data;
    		}else{
    			alert(data.msg);
    		}
		});
	}
	$scope.find();
	//按钮点击事件-条件查询
	$scope.select = function(){
    	$scope.page.current = 1;
    	$scope.find();
    }
	$scope.saveForm = function(){
		var values = [];
		$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
			values.push($(this).val());
		});
		if(values.length < 1){
			eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
		}else if(values.length > 1){
			eventBusService.publish('modal.alert', {"title":"操作提示","content":"您选择了多行数据，请重新选择。"});
		}else{
			if($scope.formCheck()){
				$scope.form.fk_teacher = values[0];
				httpService.post(app.urls.class_selectClassTeacher,$scope.form,function(data){
					if("0000" === data.code) {
						if (data.data.length == 0) {
							httpService.post(app.urls.class_updateClassTeacher, $scope.form, function (data) {
								if ("0000" === data.code) {
									httpService.post(app.urls.class_insertClassTeacher, $scope.form, function (data) {
										if ("0000" === data.code) {
											eventBusService.publish("content.page.reload", data);
											eventBusService.publish("modal.page.close", {});
										} else {
											alert(data.msg);
										}
									});
								} else {
									alert(data.msg);
								}
							});
						} else {
							alert("该教师已经是班主任了");
						}
					}else{
						alert(data.msg);
					}
				});
			}
		}
	}
}}});